﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SJZD_TypeManage : ATPages
{
    ZSql zsql = new ZSql();

    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hfxs.Value = Request.QueryString["moduid"].ToString();
            lblwz.Text = f.getModuleidAdd(hfxs.Value);

            gdata();
         
        }
    }

    protected void lnkbtnEdit_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument.ToString();
        Response.Redirect("ClubHYprice.aspx?id=" + id + "&moduid=" + hfxs.Value + "&action=update");

    }
    protected void lnkbtnFlag_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument.ToString();
        Response.Redirect("ClubHYprice.aspx?id=" + id + "&moduid=" + hfxs.Value + "&action=flag");

    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("ClubHYprice.aspx?moduid=" + hfxs.Value + "&action=add");
    }

    protected void btndel_Click(object sender, EventArgs e)
    {
        ZSql del = new ZSql();
        ZSql del1 = new ZSql();
        int n = 0;
        if (this.GvDataType.Rows.Count > 0)
        {
            for (int i = 0; i < GvDataType.Rows.Count; i++)
            {
                CheckBox ck = GvDataType.Rows[i].Cells[7].FindControl("chkDelete") as CheckBox;
                if (ck.Checked)
                {

                    del.Open("delete CS_Club  where id=" + this.GvDataType.Rows[i].Cells[0].Text);
                    del1.Open("delete CS_ClupMenber  where clup_zid=" + this.GvDataType.Rows[i].Cells[0].Text);
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('删除成功');", true);
                }
                else
                {
                    n++;
                }

                if (n == this.GvDataType.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }

            }
        }
    }

    protected void btnallflag_Click(object sender, EventArgs e)
    {
       
        ZSql allflag = new ZSql();
        int n = 0;
        if (this.GvDataType.Rows.Count > 0)
        {
            for (int i = 0; i < GvDataType.Rows.Count; i++)
            {
                CheckBox ck = GvDataType.Rows[i].Cells[7].FindControl("chkDelete") as CheckBox;
                if (ck.Checked)
                {
                   
                   
                    int flag = 1;

                    allflag.Open("update CS_Club set AuditState=" + flag + " where id=" + this.GvDataType.Rows[i].Cells[0].Text);
                       
                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('审核成功');", true);
                }
                else
                {
                    n++;
                }

                if (n == this.GvDataType.Rows.Count)
                {

                    ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('至少应选择一项')", true);
                }

              
            }
        }

    }


    private void gdata()
    {
        string sql = "select * ,Convert(char(10),EditDate,120) as EditDate1 from CS_Club ";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }

    protected void btnSelec_Click(object sender, EventArgs e)
    {

        string sql = "select * ,Convert(char(10),EditDate,120) as EditDate1 from CS_Club where hy_name like'%" + Common.FormatParameter(txtselecName.Text) + "%'";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;

    }

    protected void GvDataType_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //f.flag(GvDataType, "ComoditiesType", "TypeId", 5);

        f.checkLevels(Request.Cookies["user"].Values["roleid"], hfxs.Value, 7, GvDataType, btndel, btnallflag, btnAdd);
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string AuditState = DataBinder.Eval(e.Row.DataItem, "AuditState").ToString();

            if (AuditState == "1")
            {
                e.Row.Cells[6].Text = "已通过";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#ff0000");
            }
            if (AuditState == "0")
              { 
            e.Row.Cells[5].Text = "未通过";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#ff0000");
              }
              if (AuditState == "")
              {
                  e.Row.Cells[6].Text = "未审核";
                  e.Row.Cells[6].ForeColor = System.Drawing.Color.FromName("#ff0000");
              }
        }
        ZSql gs = new ZSql();
        if(GvDataType.Rows.Count>0)
        {
              for(int i=0;i<GvDataType.Rows.Count;i++)
            {
                gs.Open("select * from CS_ClupMenber where clup_zid =" + Convert.ToInt32(GvDataType.Rows[i].Cells[0].Text) + "");
               if (gs.m_table.Rows.Count > 0)
               {
                   GvDataType.Rows[i].Cells[2].Text = gs.m_table.Rows.Count.ToString();
               }
               else
               {
                   GvDataType.Rows[i].Cells[2].Text = "0";
               }
            }
        }
    }
}
